title: Terraform Crash Course - 1 Hour to Infrastructure as Code
subtitle: Your fast path to provisioning like a pro
author: Nemish Kanwar
date: 2025-07-16
tags: [terraform, infrastructure-as-code, tutorial, devops]Terraform Crash Course - 1 Hour to Infrastructure as Code
Title: Terraform Crash Course β 1 Hour to Infrastructure as Code
Subtitle: Your fast path to provisioning like a pro
.tf file: provision a file on your system.Title: Manual Infrastructure: What's the Problem?
Manual setup used to be the norm β clicking around in cloud consoles, tweaking config files, spinning up servers by hand.
But as environments grew more complex, this approach began to break down:
Title: What is Infrastructure as Code?
Infrastructure as Code (IaC) means managing your servers, databases, networks, and other infrastructure just like application code β using files that are versioned, shareable, and automated.
Think of it like a Dockerfile β but for your entire infrastructure stack.
IaC helps eliminate βsnowflake environmentsβ and turns infrastructure into reliable, testable, reviewable artifacts.
Title: Why Choose Terraform?
Terraform is one of the most widely adopted tools for managing infrastructure as code β and for good reason. It strikes a powerful balance between flexibility, scalability, and ease of use.
Use the same tool and workflow to manage resources across AWS, Azure, GCP, and more β or even across multiple providers at the same time.
βWrite once, apply anywhere.β
You describe what infrastructure you want (not how to build it), using Terraformβs human-friendly configuration language (HCL).
Define infrastructure components (e.g., VPCs, databases, EC2s) once and reuse them across environments, teams, or projects.
Write less, scale more.
Terraform knows the difference between what exists and what should exist, helping detect configuration drift and manage changes safely.
Thousands of ready-made modules and providers on the Terraform Registry β from HashiCorp and the community.
Speeds up onboarding, prototyping, and production deployments.
Terraform lets you scale with confidence β across clouds, teams, and time.
Title: Terraformβs Architecture
Terraform follows a simple but powerful workflow to manage infrastructure consistently and predictably.
.tf filesterraform plan.tf files) to what already exists and shows what will change β without making any changes yet.terraform applyterraform.tfstate)Example: AWS provider converts
.tfconfig into real EC2 instances, S3 buckets, etc.
This architecture is what lets Terraform manage real-world infrastructure using simple config files.
Title: Installing Terraform (Quick Guide)
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
choco install terraform Check:
terraform -version
Title: Terraform Core Concepts
To use Terraform effectively, you only need to understand a few foundational building blocks. These concepts are simple, but incredibly powerful when combined.
Plugins that let Terraform talk to specific platforms and services.
Examples: AWS, Azure, Google Cloud, Kubernetes, Docker, Local.
Terraform gives you a small set of concepts to master β and with them, you can manage anything from storage buckets to full ML workflows on GCP.
provider "google" {
project = "ml-infra-demo"
region = "us-central1"
}
The actual infrastructure you want to create β servers, buckets, files, etc.
Google Cloud Storage (GCS):
resource "google_storage_bucket" "data_bucket" {
name = "ml-pipeline-data-bucket"
location = "US"
}
Kubeflow Pipelines (via GKE):
resource "google_container_cluster" "kfp_cluster" {
name = "kfp-cluster"
location = "us-central1"
initial_node_count = 1
node_config {
machine_type = "e2-standard-2"
}
}
Make your configs dynamic and reusable.
variable "bucket_name" {
default = "ml-data-bucket"
}
# Use with:
name = var.bucket_name
Group related resources into reusable components.
Great for DRY code and scaling to real projects.
module "gcs_bucket" {
source = "./terraform-google-modules/cloud-storage/google"
version = "~> 3.0"
name = var.bucket_name
project_id = var.project
location = "US"
}
Terraform uses a .tfstate file to track what it deployed.
terraform {
backend "gcs" {
bucket = "terraform-state-storage"
prefix = "ml-infra"
}
}
Master these five and you can manage any infrastructure at scale.
Key Learning Objectives:
This is a progressive Terraform tutorial/learning repository that demonstrates core Terraform concepts through hands-on examples using the local provider to create files. Each numbered directory represents a learning module that builds upon previous concepts:
Dive into the complete code examples here:
https://github.com/Nempickaxe/terraform_basics
Run:
terraform init
terraform plan
terraform apply
Title: Terraform Workflow
Terraform uses a clean, predictable workflow to help you safely manage infrastructure β from creation to teardown.
terraform initInitializes the working directory for Terraform.
.terraform/ folder locally.terraform init
terraform planShows you exactly what Terraform will do β without making any changes.
.tf files) with existing infrastructure (state).terraform plan
Use this to double-check before applying β catch mistakes early.
terraform applyExecutes the changes described in the plan.
terraform apply
You can also use
-auto-approve, but not recommended for production.
terraform destroySafely tears down all resources defined in your configuration.
terraform destroy
Tip: Treat your Terraform workflow like
git β plan before apply, and destroy with intention.
βWrite code β Plan it β Apply it β Revert when needed.β
Title: What is terraform.tfstate?
Terraform uses a special file to keep track of what it created, updated, or destroyed β so it knows exactly whatβs real, and whatβs just in code.
terraform.tfstate is:.tf files) to the actual infrastructure on your cloud provider.plan and apply to determine what needs to change. Think of
terraform.tfstate as Terraformβs memory β without it, it has no idea what it built.
Title: Reusability with Variables
Hardcoding values is fine β until you need to scale, reuse, or collaborate. Terraform lets you make your configurations flexible and dynamic using variables and outputs.
Variables let you parameterize your infrastructure configs.
variable "file_content" {
default = "Hello Team!"
}
string, number, bool, list, map, and morevariables.tf, values passed via:
terraform.tfvars-var CLI flagsOutputs let you expose useful info from your infrastructure β like IP addresses, bucket URLs, or filenames.
output "file_path" {
value = local_file.hello_file.filename
}
terraform apply Pro Tip: Create a
terraform.tfvars file to override default values cleanly:
file_content = "Hello from the team!"
Variables make your code flexible. Outputs make it visible.
Title: Terraform Best Practices
Always use
terraform plan before apply
Store state securely (remote backend for real infra)
Use variables for anything configurable
Group logic into modules for reusability
Keep secrets out of
.tf files
Title: In Just One Hour You Learned:
.tf config Youβve now deployed infrastructure as code!